package com.boot.contorller;

import com.boot.business.PurchaseDTO;
import com.boot.feign.OrderFeign;
import com.boot.result.Result;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@AllArgsConstructor
public class OrderFallbackConsumer {
    private OrderFeign orderFeign;

    @RabbitListener(queues = "${business.mq.order-fallback-queue}")
    public void processOrderFallback(PurchaseDTO purchaseDTO) {
        try {
            log.info("处理队列中的订单：{}" + purchaseDTO.getProductId());
            Result result = orderFeign.createOrder(purchaseDTO);
            if (result.getCode() == 200) {
                log.info("订单处理成功：{}" + result.getData());
            } else {
                log.error("订单处理失败：{}" + result.getData());
            }
        } catch (Exception e) {
            log.error("订单处理异常：{}" + e.getMessage());
        }
    }
}
